package addon.w3.w3x;

import java.io.IOException;

import addon.w3.mdx.LEDataInputStream;

public class W3XTreeData extends W3XCom {
	public String treeID;
	public int variation;
	public float coordX, coordY, coordZ;
	public float angle;
	
	public float scalX, scalY, scalZ;
	
	public byte flags;
	public byte life;
	public int number;
	
	public W3XTreeData(LEDataInputStream lein) {
		this.lein = lein;
	}
	/*

	Data
	Each tree is defined by a block of 50 bytes organized like this:
	char[4]: Tree ID (can be found in the file "Units\DestructableData.slk")
	int: Variation (little endian)
	float: Tree X coordinate on the map
	float: Tree Y coordinate on the map
	float: Tree Z coordinate on the map
	float: Tree angle (radian angle value)(degree = radian*180/pi)
	float: Tree X scale
	float: Tree Y scale
	float: Tree Z scale
	byte: Tree flags*
	byte: Tree life (integer stored in %, 100% is 0x64, 170% is 0xAA for example)
	int: unknown (-1)
	int: unknown (0)
	int: Tree ID number in the World Editor (little endian) (each tree has a different one)

	*flags:
	0= invisible and non-solid tree
	1= visible but non-solid tree
	2= normal tree (visible and solid)

	To sum up how it looks:
	tt tt tt tt vv vv vv vv xx xx xx xx yy yy yy yy zz zz zz zz aa aa aa aa xs xs xs xs ys ys ys ys zs 
	zs zs zs ff ll bb bb bb bb cc cc cc cc dd dd dd dd
	where:
	tt: type
	vv: variation
	xx: x coordinate
	yy: y coordinate
	zz: z coordinates
	aa: rotation angle
	xs: x scale
	ys: y scale
	zs: z scale
	ff: flags
	ll: life
	bb: unknown
	cc: unknown
	dd: doodad number in the editor
	*/
	@Override
	public void _decode() throws W3XException, IOException {
		byte id[] = new byte[4];
		lein.read(id);
		treeID = new String(id);
		variation = lein.readInt();
		coordX = lein.readFloat();
		coordY = lein.readFloat();
		coordZ = lein.readFloat();
		angle = lein.readFloat();
		
		scalX = lein.readFloat();
		scalY = lein.readFloat();
		scalZ = lein.readFloat();
		
		flags = lein.readByte();
		life = lein.readByte();
		
		lein.readInt(); //unknown
		lein.readInt(); //unknown
		
		number = lein.readInt();
		
//		System.out.println("---------------------------------------------------");
//		System.out.println("id:"+treeID);
//		System.out.println("variation:"+variation);
//		System.out.println("coordX:"+coordX);
//		System.out.println("coordY:"+coordY);
//		System.out.println("coordZ:"+coordZ);
//		System.out.println("angle:"+angle);
//		System.out.println("scalX:"+scalX);
//		System.out.println("scalY:"+scalY);
//		System.out.println("scalZ:"+scalZ);
//		System.out.println("flags:"+flags);
//		System.out.println("life:"+life);
//		System.out.println("num:"+number);
	}
}
